﻿using System;
using System.Data;

namespace wuliuback
{
    public partial class QueryUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userName = Request["user_id"];
            string mobile = Request["mobile"];
            string user_id = Request["user_id"];
            string type = Request["type"];//1-用户名，2-手机号码，3-用户id
            string user_type = Request["user_type"];

            string code = "";
            string msg = "";
            string user = "";

            if ((userName == null || userName.Length <= 0) && (mobile == null  || mobile.Length <= 0))
            {
                msg = "用户名为空";
                code = "-1";
                user = "\"\"";
                Response.Output.WriteLine("{\"code\":\"" + code + "\",\"msg\":\"" + msg + "\",\"user\":" + user + "}");
                return;
            }
            string sql = "select * from t_user where 1=1 ";
            if (type == "1")
            {
                sql = sql+"and user_id='" + userName + "'";
            }
            else if (type == "2")
            {
                sql = sql + "and mobile='" + mobile + "'";
            }
            else
            {
                sql = sql + " and user_id='" + user_id + "'";
            }
            if (user_type != null && user_type.Length > 0)
            {
                sql = sql + " and user_type='"+user_type+"' ";
            }
            DbHelper dbHelper=new DbHelper();
            DataSet dataSet = dbHelper.Select(sql);
            DataTable table=dataSet.Tables[0];
            if (table.Rows.Count <= 0)
            {
                msg = "无此用户";
                code = "-1";
                user = "\"\"";
            }
            else
            {
                code = "0";
                user=JsonUtil.DataTableToJson(table);
            }
            
            Response.Output.WriteLine("{\"code\":\""+code+"\",\"msg\":\""+msg+"\",\"user\":"+user+"}");
        }
    }
}
